﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:WpfLoadingLibrary"
    >
    
    <Style x:Key="CancelButtonStyle"  TargetType="Button">
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="Button">
                    <Grid Background="Transparent">
                        <Border Width="12" Height="12">
                            <Path Data="M0,0 L1,1 M0,1 L1,0" Stretch="Uniform" Stroke="{TemplateBinding Foreground}" StrokeThickness="2" />
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="Blue" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="True">
                            <Setter Property="Foreground" Value="SkyBlue" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>


    <Style x:Key="LoadingCircleStyle" TargetType="ContentControl">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="IsHitTestVisible" Value="False" />
        <Setter Property="SnapsToDevicePixels" Value="False" />
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ContentControl">
                    <Image Source="images\loading.png"  Stretch="None" Name="loadingImg" >
                        <Image.RenderTransform>
                            <RotateTransform  CenterX="25" CenterY="25"/>
                        </Image.RenderTransform>
                        <Image.Style>
                            <Style>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=local:BusyAdorner},Path=Visibility}" Value="Visible">
                                        <DataTrigger.EnterActions>
                                            <BeginStoryboard Name="rotatingStoryboard">
                                                <Storyboard>
                                                    <DoubleAnimation
                                        Storyboard.Target="{Binding TemplatedParent}"
                                        Storyboard.TargetProperty="(Image.RenderTransform).(RotateTransform.Angle)"
                                        From="0" To="360" Duration="0:0:1" RepeatBehavior="Forever"/>
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </DataTrigger.EnterActions>
                                        <DataTrigger.ExitActions>
                                            <RemoveStoryboard BeginStoryboardName="rotatingStoryboard"/>
                                        </DataTrigger.ExitActions>
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </Image.Style>
                    </Image>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type local:BusyChrome}">
        <Setter Property="Opacity" Value="1" />
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:BusyChrome}">
                    <Grid>
                        <Border>

                            <Border.Background>
                                <DrawingBrush Viewport="0,0,1,1"  ViewboxUnits="Absolute">
                                    <DrawingBrush.Drawing>
                                        <DrawingGroup>

                                            <GeometryDrawing Brush="#4000">
                                                <GeometryDrawing.Geometry>
                                                    <RectangleGeometry Rect="0,0,1,1" />
                                                </GeometryDrawing.Geometry>
                                            </GeometryDrawing>
                                        </DrawingGroup>
                                    </DrawingBrush.Drawing>
                                </DrawingBrush>
                            </Border.Background>
                        </Border>
                        <Border HorizontalAlignment="Center" VerticalAlignment="Center" Background="Transparent" BorderThickness="0">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <StackPanel Height="60" Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                                    <ContentControl   Style="{StaticResource LoadingCircleStyle}" />
                                    <Label Name="PART_Text"  FontSize="22" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,4,0"></Label>
                                </StackPanel>
                                <GridSplitter Grid.Column="1" Background="#323232" IsEnabled="False" Width="1"  Visibility="Collapsed"/>
                                <Button Name="PART_Cancel" Width="60" Style="{StaticResource CancelButtonStyle}" Grid.Column="2" Visibility="Collapsed"/>
                            </Grid>
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
